package logic

import (
	"context"

	"go-weixin/app/guitar/model"
	"go-weixin/app/guitar/rpc/internal/svc"
	"go-weixin/app/guitar/rpc/pb/proto/guitar"

	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/x/errors"
)

type GuitarImageUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGuitarImageUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GuitarImageUpdateLogic {
	return &GuitarImageUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GuitarImageUpdateLogic) GuitarImageUpdate(in *guitar.GuitarImageUpdateReq) (*guitar.GuitarImageUpdateResp, error) {
	affected, err := l.svcCtx.ChenDb.ID(in.Id).Update(&model.GuitarImageModel{Url: in.Url})
	if err != nil {
		return nil, errors.New(8000, "guitar.image.update:mysql:"+err.Error())
	}
	if affected == 0 {
		return nil, errors.New(7000, "guitar.image.update:mysql:affected=0!!")
	}

	return &guitar.GuitarImageUpdateResp{}, nil
}
